package fun.rockchen.controller;

import fun.rockchen.anno.SystemControllerLog;
import fun.rockchen.anno.TokenValidate;
import fun.rockchen.bean.MapTaskEntity;
import fun.rockchen.bean.User;
import fun.rockchen.bean.UserMapTag;
import fun.rockchen.service.interfaceService.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author Rock Chen
 * @Description:
 * @date 2023/10/15 19:38
 */

@SystemControllerLog(operation = "用户模块", type = "info")
@RequestMapping("/api/user")
@RestController
public class UserController {
    private final UserService userService;

    @Autowired
    public UserController(UserService userService) {
        this.userService = userService;
    }

    @PostMapping("/userLogin")
    public ResponseEntity<?> validateUserLogin(@RequestBody User user) {
        return userService.getUserInfo(user);
    }

    @PostMapping("/userRegister")
    public ResponseEntity<?> validateUserRegister(@RequestBody User user) {
        // todo 验证前端传来的数据
        return userService.addUserInfo(user);
    }

    @TokenValidate(operation = "--------token校验--------")
    @DeleteMapping
    public ResponseEntity<?> deleteUser(@RequestBody MapTaskEntity mapTaskEntity) {
        return userService.deleteUser(mapTaskEntity);
    }

    @TokenValidate(operation = "--------token校验--------")
    @PutMapping
    public ResponseEntity<?> updateUserTag(@RequestBody MapTaskEntity mapTaskEntity) {
        return userService.updateUserTag(mapTaskEntity);
    }

    @TokenValidate(operation = "--------token校验--------")
    @GetMapping("/userTag")
    public ResponseEntity<?> getUserTag(@RequestParam String id) {
        return userService.getUserTag(id);
    }

    @TokenValidate(operation = "--------token校验--------")
    @PostMapping("/userTag")
    public ResponseEntity<?> addUserTag(@RequestBody UserMapTag userMapTag) {
        return userService.addUserTag(userMapTag);
    }
}
